package com.db;

import java.util.List;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public abstract class AbstractDAO <T> {

	public static final String USERNAME = "root";
	public static final String USERPASSWORD = "pass";
	public static final String DB_URL = "jdbc:mysql://localhost/univer?user=" + USERNAME + "&password=" + USERPASSWORD;
	
	protected Connection connection = null;

	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			System.err.println("Driver not found");
			e.printStackTrace();
		}
	}
	
	
	protected Connection getConnection() throws SQLException {
		return DriverManager.getConnection(DB_URL);
	}
	
	
	protected void closeConnection()
	{
		try{
		if (connection != null){
			connection.close();
		}
		}
				
		catch (SQLException e)
		{
			System.err.println("Failed to close connection");
			e.printStackTrace();
		}
	}
	
	public abstract void add (T entity);
	public abstract List <T> getAll ();
	public abstract void delete (int id);
	public abstract T getById (int id) throws SQLException;
	//public abstract void update (T entity);
	
	
}
	
	
	
	

